package czh.cocoa.ui;

import android.graphics.Paint;
import czh.cocoa.foundation.NSObject;
import czh.cocoa.foundation.NSString;
import czh.cocoa.graphics.CGFont;

public class UIFont extends NSObject {

	private NSString mFontName;
	
	private float mFontSize;
	
	private Paint mPaint;
	
	public static UIFont systemFontOfSize(float fontSize) {
		UIFont font = new UIFont();
		font.mFontName = CGFont.DEFAULT_FONT_NAME;
		font.mFontSize = fontSize;
		return font;
	}
	
	public static UIFont boldSystemFontOfSize(float fontSize) {
		UIFont font = new UIFont();
		font.mFontName = CGFont.DEFAULT_BOLD_FONT_NAME;
		font.mFontSize = fontSize;
		return font;
	}
	
	public static UIFont italicSystemFontOfSize(float fontSize) {
		UIFont font = new UIFont();
		font.mFontName = CGFont.DEFAULT_ITALIC_FONT_NAME;
		font.mFontSize = fontSize;
		return font;
	}
	
	private UIFont() {
		
	}
	
	public UIFont fontWithSize(float fontSize) {
		UIFont font = new UIFont();
		font.mFontName = new NSString(mFontName); 
		font.mFontSize = fontSize;
		return font;
	}
	
	public NSString fontName() {
		return mFontName;
	}
	
	public float pointSize() {
		return mFontSize;
	}
	
	public float ascender() {
		if (mPaint == null) {
			mPaint = new Paint();
			CGFont font = new CGFont(mFontName);
			mPaint.setTypeface(font.typeface());
			mPaint.setTextSize(mFontSize);
		}
		return -mPaint.ascent();
	}
	
	public float descender() {
		if (mPaint == null) {
			mPaint = new Paint();
			CGFont font = new CGFont(mFontName);
			mPaint.setTypeface(font.typeface());
			mPaint.setTextSize(mFontSize);
		}
		return -mPaint.descent();
	}
	
}
